
function expend_icon_status(){
//直接改样式
//	$('div.task a.expend_fold i').css("color",'');
//	$('div.task').parents('div.task').children("a.expend_fold").children("i").css("color",'red');

//改属性，通过属性影响样式
	$('div.task').attr('data-haschild','');
	$('div.task').parents('div.task').attr('data-haschild','1');
}

//只修改指定dom和其父节点
function expend_icon_status_dom(jquery_select){
	// console.log(jquery_select);
	//改属性，通过属性影响样式
	if(jquery_select){
		// $(jquery_select).attr('data-haschild','');
		// console.log($(jquery_select).find("div.task").parents("div.task"));
		$(jquery_select).find("div.task").parents("div.task").attr("data-haschild",'1');
	}
}


function expend_child_by_taskid(id){
		$(".task[data-taskid="+id+"]").children('div').show();
		$(".task[data-taskid="+id+"]").children('a.expend_fold').children('i').removeClass('fa-folder-o');
		$(".task[data-taskid="+id+"]").children('a.expend_fold').children('i').addClass('fa-folder-open-o');
		$(".task[data-taskid="+id+"]").children('a.expend_fold').attr('title','折叠');
}
 function expend_fold_by_taskid(id){
	if($(".task[data-taskid="+id+"]"+" a.expend_fold i").hasClass('fa-folder-o')){
		expend_child_by_taskid(id);
	}else{
		$(".task[data-taskid="+id+"]").children('div').hide();
		$(".task[data-taskid="+id+"]").children('a.expend_fold').children('i').addClass('fa-folder-o');
		$(".task[data-taskid="+id+"]").children('a.expend_fold').children('i').removeClass('fa-folder-open-o');
		$(".task[data-taskid="+id+"]").children('a.expend_fold').attr('title','展开');
	}
 }

 
function expend_child_by_domid(domid){
		$("#"+domid).children('div.task').show(200);
		$("#"+domid).children('a.expend_fold').children('i').removeClass('fa-folder-o');
		$("#"+domid).children('a.expend_fold').children('i').addClass('fa-folder-open-o');
		$("#"+domid).children('a.expend_fold').attr('title','折叠');
} 
function expend_fold_by_domid(domid){
	if($("#"+domid+">a.expend_fold i").hasClass('fa-folder-o')){
		// var taskid=$("#"+domid).attr("data-taskid");
		// $("#"+domid).append($("#904 .task[data-parent="+taskid+"]"));

		expend_icon_status_dom("#"+domid);
//		expend_icon_status();

		$("#"+domid).children('div.task').show(200);
		// $("#"+domid).children('a.expend_fold').children('i').removeClass('fa-folder-o');
		// $("#"+domid).children('a.expend_fold').children('i').addClass('fa-folder-open-o');
		// $("#"+domid).children('a.expend_fold').attr('title','折叠');

		$("#"+domid + '>a.expend_fold>i').removeClass('fa-folder-o');
		$("#"+domid + '>a.expend_fold>i').addClass('fa-folder-open-o');
		$("#"+domid + '>a.expend_fold').attr('title','折叠');
	
	//以兼容包裹了task_head头的情形
		$("#"+domid + '>.task_hdad a.expend_fold>i').removeClass('fa-folder-o');
		$("#"+domid + '>.task_head a.expend_fold>i').addClass('fa-folder-open-o');
		$("#"+domid + '>.task_head a.expend_fold').attr('title','折叠');
	}else{
		$("#"+domid).children('div.task').hide(200);
		// $("#"+domid).children('a.expend_fold').children('i').addClass('fa-folder-o');
		// $("#"+domid).children('a.expend_fold').children('i').removeClass('fa-folder-open-o');
		// $("#"+domid).children('a.expend_fold').attr('title','展开');

		$("#"+domid + '>a.expend_fold>i').removeClass('fa-folder-open-o');
		$("#"+domid + '>a.expend_fold>i').addClass('fa-folder-o');
		$("#"+domid + '>a.expend_fold').attr('title','折叠');
	
	//以兼容包裹了task_head头的情形
		$("#"+domid + '>.task_hdad a.expend_fold>i').removeClass('fa-folder-open-o');
		$("#"+domid + '>.task_head a.expend_fold>i').addClass('fa-folder-o');
		$("#"+domid + '>.task_head a.expend_fold').attr('title','展开');
	}
 }

 //展开节点操作
 function expend_by_domid(domid){
	//  console.log("expend");
	expend_icon_status_dom("#"+domid);
	$("#"+domid).children('div.task').show(200);
	// console.log($("#"+domid+'>a.expend_fold>i'));
	$("#"+domid + '>a.expend_fold>i').removeClass('fa-folder-o');
	$("#"+domid + '>a.expend_fold>i').addClass('fa-folder-open-o');
	$("#"+domid + '>a.expend_fold').attr('title','折叠');

//以兼容包裹了task_head头的情形
	$("#"+domid + '>.task_head>a.expend_fold>i').removeClass('fa-folder-o');
	$("#"+domid + '>.task_head>a.expend_fold>i').addClass('fa-folder-open-o');
	$("#"+domid + '>.task_head>a.expend_fold').attr('title','折叠');
 }

//折叠节点操作
 function fold_by_domid(domid){
	//  console.log("fold");
	// console.log(domid);
	// console.log($("#"+domid+'>a.expend_fold>i'));
	// expend_icon_status_dom("#"+domid);
	$("#"+domid).children('div.task').hide(200);

	$("#"+domid + '>a.expend_fold>i').removeClass('fa-folder-open-o');
	$("#"+domid + '>a.expend_fold>i').addClass('fa-folder-o');
	$("#"+domid + '>a.expend_fold').attr('title','折叠');

//以兼容包裹了task_head头的情形
	$("#"+domid + '>.task_head>a.expend_fold>i').removeClass('fa-folder-open-o');
	$("#"+domid + '>.task_head>a.expend_fold>i').addClass('fa-folder-o');
	$("#"+domid + '>.task_head>a.expend_fold').attr('title','展开');
 }

 function expend_fold_by_jquery_dom(domid){
	if($(domid).children('a.expend_fold').children('i').hasClass('fa-folder-o')){
		$(domid).children('div').show();
		$(domid).children('a.expend_fold').children('i').removeClass('fa-folder-o');
		$(domid).children('a.expend_fold').children('i').addClass('fa-folder-open-o');
		$(domid).children('a.expend_fold').attr('title','折叠');
	}else{
		$(domid).children('div').hide();
		$(domid).children('a.expend_fold').children('i').addClass('fa-folder-o');
		$(domid).children('a.expend_fold').children('i').removeClass('fa-folder-open-o');
		$(domid).children('a.expend_fold').attr('title','展开');
	}
 }

 $(document).ready(function() {
//设置折叠展开按钮的行为
//            $("#simple_view,#alltask_view,#search_view,#help_view").delegate('a.expend_fold', 'click', function(e) {
            $("body").on('click','a.expend_fold',  function(e) {
                var event = e || event; //为兼容firefox的事件模型
                			// console.log(event.target);
                var domid = $(event.target).closest("div.task").attr("id");
							// console.log(domid);
				// console.log($(event.target).closest("a.expend_fold"));	
				if($(event.target).closest("a.expend_fold").children("i").hasClass('fa-folder-o')){
					expend_by_domid(domid);
				}else{
					fold_by_domid(domid);
				}
            });

});